import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../providers/home_provider.dart';
import 'device_list_page.dart';
import 'profile_page.dart';

class HomePage extends ConsumerWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final currentIndex = ref.watch(homeTabStateProvider);

    return Scaffold(
      body: IndexedStack(
        index: currentIndex,
        children: const [
          DeviceListPage(),
          ProfilePage(),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: currentIndex,
        onTap: (index) {
          ref.read(homeTabStateProvider.notifier).selectTab(index);
        },
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.devices),
            label: '设备列表',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.person),
            label: '我的',
          ),
        ],
      ),
    );
  }
}
